package com.ljb.utilslibrary.commUtils;

import android.content.Context;

import java.io.IOException;
import java.io.InputStream;

/**
 * 资源文件工具类
 * Created by ljb on 2017/6/29.
 */

public class AssetsUtils {

    private AssetsUtils() {
    }

    /**
     * 获取资源文件中的文件内容
     *
     * @param c        上下文
     * @param fileName 文件全程,包括后缀
     * @return 文件中的字符串
     */
    public static String getDataFromAssets(Context c, String fileName) {
        InputStream is = null;
        try {
            is = c.getAssets().open(fileName);
            int size = is.available();
            byte[] buffer = new byte[size];
            is.read(buffer);
            is.close();
            return new String(buffer, "utf-8");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (is != null) {
                    is.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        return null;
    }
}
